using System;
using System.Collections.Generic;
using MieMieFrameTools;
using UnityEngine;

public class EventCenterExample : Singleton<EventCenterExample>
{
   public Action OnEvent;

   private Dictionary<string,Action> eventDic = new();

   public void AddEvent(string eventName,Action action)
   {
      if(eventDic.ContainsKey(eventName))
      {
         eventDic[eventName] += action;
      }
      else
      {
         eventDic.Add(eventName,action);
      }
   }

   public void RemoveEvent(string eventName,Action action){
        if(eventDic.ContainsKey(eventName))
        {
            eventDic[eventName] -= action;
        }else{
            Debug.Log("事件不存在");
        }
   }

   public void TriggerEvent(string eventName){
    if(eventDic.ContainsKey(eventName)){
        eventDic[eventName]?.Invoke();
    }else{
        Debug.Log("事件不存在");
    }
   }
   
}
